#include <Arduino.h>
#include <Wire.h>
#include "SSD1306Wire.h"
#include "HX711.h"
//屏幕初始化
SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL

//称重初始化
#define Weight_raw 68400
#define Weight_factor 210
HX711 scale;
const int LOADCELL_DOUT_PIN = 14;
const int LOADCELL_SCK_PIN = 27;

int a = 0;

void setup()
{
  //屏幕初始化
  display.init();
  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_16);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  //称重初始化
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}

void loop()
{
  // clear the display
  display.clear();
  //读取原始数据
  long reading = scale.read_average(1);//以一次平均值读取
  long raw_data=-reading;
  float data =(raw_data-Weight_raw);//原始数据-校准数据
  display.drawString(0, 0, "raw :");
  display.drawString(50, 0, String(scale.read()));
  display.drawString(0, 20, "weight :");
  display.drawString(60, 20, String(data/Weight_factor));//校准数据/称重因子=重量
  display.drawString(0, 40, String(getCpuFrequencyMhz()));
  display.drawString(60, 40, String((int)data/Weight_factor));
  a++;
  display.display();
}
